package by.ins.utils.devhelpers;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;

import by.ins.app.AppContext;

public class StartUpAppTaskHelper {
	//isExist()	
	private static final Logger log = LogManager.getLogger(StartUpAppTaskHelper.class);
	
	protected int first;
	protected int last;
	protected List<Command> commands;
	
	
	public int getFirst() {
		return first;
	}
	public void setFirst(int first) {
		this.first = first;
	}
	public int getLast() {
		return last;
	}
	public void setLast(int last) {
		this.last = last;
	}
	
	public List<Command> getCommands() {
		if(commands == null){
			initFromContext();
			if(commands == null){
				commands = new ArrayList<Command>(0);
			}
		}
		return commands;
	}
	
/*	public void setCommands(List<Command> commands) {
		this.commands = commands;
	}
*/	

	protected void initFromContext(){
		commands = new ArrayList<Command>(); 
		for(int i = first ; i <= last; i++ ){
			try{
				Command comm=  (Command)AppContext.getBean("c_" + i);
				if(comm != null){
					commands.add(comm);
				}
			}catch (Exception e) {
			 log.error("", e);
			}
		}
	}
}
